package ysq.xyg.wxapi.service.impl;

import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import ysq.xyg.base.util.FileUtil;
import ysq.xyg.web.model.po.WebAccount;
import ysq.xyg.wxapi.dao.WxDao;
import ysq.xyg.wxapi.model.base.MsgRequest;
import ysq.xyg.wxapi.model.base.MsgType;
import ysq.xyg.wxapi.service.WxService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/6/23 0023.
 */
@Service("wxService")
public class WxServiceImpl implements WxService {

    @Resource
    private WxDao wxDao;

    /**
     * 微信消息管理
     * */
    @Override
    public String wxManager(HttpServletRequest request, MsgRequest msgRequest, WebAccount webAccount){
        // 项目在容器中实际发布运行的根路径
        String realPath= FileUtil.acceptRealPath(request);

        String msgtype = msgRequest.getMsgType();//接收到的消息类型
        String respXml = null;//返回的内容；
        if(msgtype.equals(MsgType.Text.toString())){
           //文本消息
            respXml = wxDao.msgResponseText(msgRequest,webAccount);
        }else if(msgtype.equals(MsgType.Image.toString())){//图片消息
            //图片
            respXml = wxDao.msgResponseImage(realPath,msgRequest,webAccount);
        }else if(msgtype.equals(MsgType.Location.toString())){//地理位置消息

        }

        return respXml;
    }

}
